package com.itheima.mapper;

import com.itheima.pojo.PageBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.awt.print.Book;
import java.util.List;

@Mapper
public interface BookMapper {
    //分组查询
    @Select("select * from library")
    List<Book> get();

    //新增
    void save(Book book);

    //根据id查询
    @Select("select * from library where id = #{id}")
    Book getById(Integer id);

    //根据id修改图书信息
    void update(Book book);

    //根据id删除，只有管理员可以删除
    @Delete("delete from library where id = #{id}")
    void delete(List<Integer> id);

    //借阅图书，减少图书库存
    @Update("update library set stock = stock - 1 where id = #{bookId}")
    void reduceStock(Integer bookId);

    //归还图书，增加图书库存
    @Update("update library set stock = stock + 1 where id = #{bookId}")
    void addStock(Integer bookId);

    PageBean getByIdAndName();

    
}
